<template>
  <div>
    <el-container>
      <el-form
        label-position="right"
        ref="form"
        :model="form"
        label-width="100px"
      >
        <el-row v-for="(subModule,index) in subModuleList" :key="subModule">{{ subModule }}:
          <el-checkbox-group v-if="index==0" v-model="form.defining_feature">
            <el-col :span="4" v-for="item in subModuleItemList[index]" :key="item">
              <el-checkbox :label="item">{{ item }}</el-checkbox>
            </el-col>
          </el-checkbox-group>
          <el-checkbox-group v-if="index==1" v-model="form.risk_group">
            <el-col :span="4" v-for="item in subModuleItemList[index]" :key="item">
              <el-checkbox :label="item">{{ item }}</el-checkbox>
            </el-col>
          </el-checkbox-group>
          <el-checkbox-group  v-if="index==2" v-model="form.risk_factor">
            <el-col :span="4" v-for="item in subModuleItemList[index]" :key="item">
              <el-checkbox :label="item">{{ item }}</el-checkbox>
            </el-col>
          </el-checkbox-group>
          <el-checkbox-group  v-if="index==3" v-model="form.relevant_factor">
            <el-col :span="4" v-for="item in subModuleItemList[index]" :key="item">
              <el-checkbox :label="item">{{ item }}</el-checkbox>
            </el-col>
          </el-checkbox-group>
          <el-checkbox-group   v-if="index==4" v-model="form.evidence">
            <el-col :span="4" v-for="item in subModuleItemList[index]" :key="item">
              <el-checkbox :label="item">{{ item }}</el-checkbox>
            </el-col>
          </el-checkbox-group>
        </el-row>
      </el-form>
    </el-container>
  </div>
</template>

<script>
var BaaS = require("minapp-sdk");
let clientID = "9ed0a3da89683e42d793";
BaaS.init(clientID);
export default {
  name: "intestinesStomach",
  props: {
    module_intestinesstomach: {
      type: String,
      default: "",
    },
  },
  data() {
    return {
      subModuleList: [ 
        "定义性特征",
        "危险人群",
        "危险因素",
        "相关因素",
        "循证知识",],
      subModuleListSet: new Set(),
      subModuleItemList: [
        [
          "残胃胆汁反流",
          "肠鸣音改变",
          "肠鸣音减弱",
          "肠鸣音亢进",
          "持续排出软便",
          "大便带有鲜红血液",
          "大便着色",
          "恶心",
          "反流",
          "腹部痉挛",
          "腹部叩诊浊音",
          "腹部体征改变",
          "腹部压痛，伴有明显的肌肉抵抗",
          "腹部压痛，不伴有明显的肌肉抵抗",
          "腹鸣",
          "腹痛",
          "腹泻",
          "腹压增加",
          "腹胀",
          "干硬成形便",
          "坚硬成形便",
          "痉挛",
          "滥用泻药",
          "老年人表现不典型",
          "明显的腹部包块",
          "明显的直肠肿块",
          "呕吐",
          "排便次数减少",
          "排便紧迫感",
          "排便困难",
          "排便量减少",
          "排便时疼痛",
          "疏忽便意",
          "水样便",
          "虽然意识到直肠充盈，但无法排出成形便",
          "吞咽增加",
          "唾液分泌增加",
          "胃残留增加",
          "胃肠道激惹",
          "胃排空加速",
          "无法排便",
          "无法识别便意",
          "无法识别直肠充盈",
          "无法延迟排便",
          "无排气",
          "稀水样便，＞3次/24小时",
          "消化不良",
          "厌食",
          "用力排便",
          "直肠充盈",
          "直肠内软糊状便",
          "直肠压力",
          "窒息感",
          "重度胃肠胀气",
        ],
        ["不卫生的烹饪暴露", "毒物暴露", "污染物暴露"],
        ["排泄物"],
        [
          "不规律的排便习惯",
          "不愉快的视觉刺激",
          "肠道排空不完全",
          "腹部肌肉虚弱",
          "肌张力普遍下降",
          "近期与环境相关的改变",
          "口腔卫生不良",
          "烹饪不卫生",
          "日均活动量低于同性别和同年龄推荐的活动量",
          "如厕习惯不良",
          "如厕自理困难",
          "水源改变",
          "胃肠活动减少",
          "习惯性抑制排便的欲望",
          "纤维性食物摄入不足",
          "压力水平增加",
          "饮食习惯不良",
          "饮食习惯改变",
          "有毒的味道",
          "与毒性环境相关的刺激",
          "与环境相关的因素",
        ],
        [
          "肠道压力异常增加",
          "肠内喂养",
          "低位运动神经损伤",
          "腹内肿瘤",
          "腹压异常增加",
          "肝包膜拉伸",
          "感染",
          "高位运动神经损伤",
          "寄生虫",
          "结直肠病变",
          "局部肿瘤",
          "颅内压（ICP）增高",
          "慢性腹泻",
          "梅尼埃病",
          "迷路炎",
          "脑膜炎",
          "脾包膜拉伸",
          "前列腺增生",
          "嵌塞",
          "妊娠",
          "生化功能障碍",
          "食管反流病",
          "食管疾病",
          "食物不耐受",
          "术后肠梗阻",
          "糖尿病",
          "铁盐",
          "脱肛",
          "胃肠道炎症",
          "胃肠循环减少",
          "胃扩张",
          "吸收不良",
          "先天性巨结肠疾病",
          "牙齿情况不良",
          "胰腺疾病",
          "运动病",
          "直肠储存能力受损",
          "直肠肛门裂",
          "直肠肛门狭窄",
          "直肠溃疡",
          "直肠括约肌功能失调",
          "直肠括约肌功能异常",
          "直肠脓肿",
          "直肠脱垂",
          "痔疮",
          "肿瘤",
        ],
      ],
      submoduleItemListSet: new Set(),
      form: {
        defining_feature: [],
        risk_group: [],
        risk_factor: [],
        relevant_factor: [],
        evidence: [],
      },
    };
  },
  methods: {
    getSubModuleItem(index) {
      for (let i = 0; i < this.subModuleList.length; i++) {
        let itemSet = new Set();
        // this.subModuleItemList[i] = []; //将当前数组的元素设置为数组就是二维数组了
        let query = new BaaS.Query();
        let overall_eval = new BaaS.TableObject("overall_eval_item");
        query.compare("module", "=", this.module_intestinesstomach);
        query.compare("submodule", "=", this.subModuleList[i]);
        overall_eval
          .setQuery(query)
          .select(["submodule", "item"])
          .limit(1000)
          .offset(index)
          .find()
          .then((res) => {
            let datas = res.data.objects;
            datas.forEach((data) => {
              itemSet.add(data.item);
            });
            if (res.data.meta.next !== null) {
              this.getSubModuleItem(index + 1000);
            } else {
              this.subModuleItemList.push(Array.from(itemSet));
            }
          });
      }
      console.log(this.subModuleItemList);
    },
    getSubModule(index) {
      let query = new BaaS.Query();
      let overall_eval = new BaaS.TableObject("overall_eval_item");
      query.compare("module", "=", this.module_intestinesstomach);
      overall_eval
        .setQuery(query)
        .select(["module", "submodule"])
        .limit(1000)
        .offset(index)
        .find()
        .then((res) => {
          let datas = res.data.objects;
          datas.forEach((data) => {
            this.subModuleListSet.add(data.submodule);
          });
          if (res.data.meta.next !== null) {
            this.getSubModule(index + 1000);
          } else {
            this.subModuleList = Array.from(this.subModuleListSet);
            console.log(this.subModuleList);
            this.getSubModuleItem(0);
          }
        });
    },
    init() {
      this.getSubModule(0);
    },
  },
  created() {
    // this.init();
  },
};
</script>

<style>
</style>